package com.explorati.design_pattern.creational.builder.example2.v2;

/**
 * 使用内部类的方式完成建造者：
 * 	在Computer中实现两个构造方法，分别传入两种类型的电脑
 * 每个电脑组装后返回computer对象return new Computer(this)
 * @Date 2019/6/15
 * @author explorati
 *
 */
public class Computer {
	// 类型
	private String type;
	// CPU
	private String cpu;
	// 内存
	private String ram;
	// 硬盘
	private String hardDisk;
	// 显示器
	private String monitor;
	// 操作系统
	private String os;
	private String graphicCard;

	public Computer(T410i computer) {
		this.type = computer.type;
		this.cpu = computer.cpu;
		this.ram = computer.ram;
		this.hardDisk = computer.hardDisk;
		this.monitor = computer.monitor;
		this.graphicCard = computer.graphicCard;
		this.os = computer.os;
	}

	public Computer(X201 computer) {
		this.type = computer.type;
		this.cpu = computer.cpu;
		this.ram = computer.ram;
		this.hardDisk = computer.hardDisk;
		this.monitor = computer.monitor;
		this.os = computer.os;
	}

	@Override
	public String toString() {
		return "型号: \t" + this.type + "\nCPU : \t" + this.cpu + "\n内存：\t" + this.ram + "\n硬盘 : \t" + this.hardDisk
				+ "\n显卡 :\t" + this.graphicCard + "\n显示器 : \t" + this.monitor + "\n操作系统 :\t" + this.os;
	}

	public static class T410i {
		// 类型  不用建造
		private String type = "T410i";
		// CPU
		private String cpu;
		// 内存
		private String ram;
		// 硬盘
		private String hardDisk;
		// 显示器
		private String monitor;
		// 操作系统
		private String os;
		private String graphicCard;

		public T410i buildCpu(String cpu) {
			this.cpu = cpu;
			return this;
		}

		public T410i buildRam(String ram) {
			this.ram = ram;
			return this;
		}

		public T410i buildHardDisk(String hardDisk) {
			this.hardDisk = hardDisk;
			return this;
		}

		public T410i buildMonitor(String monitor) {
			this.monitor = monitor;
			return this;
		}

		public T410i buildOs(String os) {
			this.os = os;
			return this;
		}

		public T410i buildGraphicCard(String graphicCard) {
			this.graphicCard = graphicCard;
			return this;
		}

		public Computer build() {
			return new Computer(this);
		}
	}

	public static class X201 {
		// 类型
		private String type;
		// CPU
		private String cpu;
		// 内存
		private String ram;
		// 硬盘
		private String hardDisk;
		// 显示器
		private String monitor;
		// 操作系统
		private String os;

		public X201 buildType(){
			this.type = "ThinkPad X201i";
			return this;
		}
		
		public X201 buildCpu() {
			this.cpu = "i3-250";
			return this;
		}

		public X201 buildRam() {
			this.ram = "2GB 1333MHz";
			return this;
		}

		public X201 buildHardDisk() {
			this.hardDisk = "250GB 5400转";
			return this;
		}

		public X201 buildMonitor() {
			this.monitor = "12英寸 1280*800";
			return this;
		}

		public X201 buildOs() {
			this.os = "Windows 7 Home版";
			return this;
		}

		public X201 buildGraphicCard(String graphicCard) {
			return this;
		}

		public Computer build() {
			return new Computer(this);
		}
	}
}
